package com.adam.management.response;

import com.adam.management.enums.ResponseCode;
import com.adam.management.enums.ResponseMsg;
import lombok.Data;

/**
 * @projectName: adam-management-system
 * @description:
 * @author: Adam
 * @create: 2019-11-04 20:59
 **/

@Data
public class ResponseData<T> {

    private int code;

    private String message;

    private T data;

    public ResponseData(){}

    public ResponseData(int code,String message,T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public ResponseData(int code,T data){
        this.code = code;
        this.data = data;
    }

    public static<T> ResponseData<T> success(T data){
        return new ResponseData<>(ResponseCode.SUCCESS_CODE.getCode(),ResponseMsg.SUCCESS_MSG.getMsg(),data);
    }
    public static<T> ResponseData<T> success(int code,String message,T data){
        return new ResponseData(code,message,data);
    }

    public static <T> ResponseData<T> fail(T data){
        return new ResponseData<>(ResponseCode.FAIL_CODE.getCode(),ResponseMsg.FAIL_MSG.getMsg(),data);
    }

    public static<T> ResponseData<T> fail(String msg){
        return new ResponseData<T>(ResponseCode.FAIL_CODE.getCode(),msg,null);
    }
    public static<T> ResponseData<T> fail(int code,String message,T data){
        return new ResponseData(code,message,data);
    }
    public static<T> ResponseData<T> fail(String message,T data){
        return new ResponseData(ResponseCode.FAIL_CODE.getCode(),message,data);
    }

}
